#!/bin/bash

source /etc/profile

if [ -n "$1" ]
then
do_date=$1
else
do_date=`date -d "-1 day" + "%Y%m%d"`
fi


sqoop=/opt/cloudera/parcels/CDH/bin/sqoop
Hive=/opt/cloudera/parcels/CDH/bin/hive

import_data(){
$sqoop import \
--connect jdbc:mysql://hadoop1:3306/lg_logstic \
--username root \
--password 7 \
--target-dir /user/hive/sttement/ods.db/$1/dt=$do_date \
--delete-target-dir \
--query "$2 and  \$CONDITIONS" \
--num-mappers 1 \
--fields-terminated-by ',' \
--null-string '\\N' \
--null-non-string '\\N'
}

import_clearing_order_item() {
  import_data clearing_order_item "select * from clearing_order_item where date_format(update_time, '%Y%m%d') = '${do_date}'"
}

import_clearing_order_item

$Hive -e "alter table ods.ods_clearing_order_item add partition(dt='$do_date')"

